package com.contain.auth.security.service;

import com.contain.auth.service.UserDetailsEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @Auther: tianchao
 * @Date: 2021/7/3 22:30
 * @Description:
 */
@Component
@Slf4j
public class UserDeatilServiceImpl implements UserDetailsService {
    @Autowired
    @Lazy
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        String password = passwordEncoder.encode("123456");
        return new UserDetailsEntity("1","tianchao",password,"1","1",AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
        //return new User("tianchao",password, AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
